package com.nowcoder.code.hjnc;

import java.io.InputStream;
import java.util.HashMap;

public class HJ5 {


    public static String in() {
        StringBuilder sb = new StringBuilder();
        InputStream in = System.in;
        char c;
        try {
            c = (char) in.read();
            while (c != '\n' && c != '\r') {
                sb.append(c);
                c = (char) in.read();
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return sb.toString();
    }


    public static void out(Object obj) {
        System.out.println(obj);
    }

    public static void main(String[] args) throws Exception {

        StringBuilder sb = new StringBuilder();
        int i;
        while ((i = System.in.read()) != -1) {
            if ((char) i == '\n' || (char) i == '\r') {
                out(hexTo10(sb.toString()));
                sb = new StringBuilder();
            } else {
                sb.append((char) i);
            }
        }
    }


    static HashMap<Character, Integer> hexMap = new HashMap<>(16);


    static {
//        int i;
//        for (i = 0; i < 10; i++) {
//            hexMap.put((char) (i + 48), i);
//        }
//        for (; i < 16; i++) {
//            hexMap.put((char) (65 + i - 10), i);
//        }


        hexMap.put('0', 0);
        hexMap.put('1', 1);
        hexMap.put('2', 2);
        hexMap.put('3', 3);
        hexMap.put('4', 4);
        hexMap.put('5', 5);
        hexMap.put('6', 6);
        hexMap.put('7', 7);
        hexMap.put('8', 8);
        hexMap.put('9', 9);

        hexMap.put('A', 10);
        hexMap.put('B', 11);
        hexMap.put('C', 12);
        hexMap.put('D', 13);
        hexMap.put('E', 14);
        hexMap.put('F', 15);
    }

    public static int hexTo10(String hex) {

        char[] chars = hex.toCharArray();
        int result = 0;

        int pow = 1;
        for (int i = chars.length - 1; i >= 2; i--) {
            int h = hexMap.get(chars[i]);
            result = result + h * pow;
            pow = pow << 4;
        }

        return result;
    }


}
